package usaco.c2009.march.bronze;

import java.util.Scanner;

/*
 * p3203
 * USACO March 2009 - Bronze
 */

public class p3203 {

	static int N, dist, budget, debt, last;
	static int[] D;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		N = scanner.nextInt();
		D = new int[N+1];
		for (int i=1;i<=N;++i) {
			D[i] = scanner.nextInt();
		}
		
		dist = N;
		debt = 0;
		budget = 0;
		last = 0;
		
		for (int i=1;i<=N;++i) {
			if (D[i] > 0) {
				budget += D[i];
			}
			else {
				debt += D[i];
				if (last == 0) {
					last = i;
				}
			}
			
			if (budget >= -debt) {
				if (debt < 0) {
					budget += debt;
					debt = 0;
					dist += 2 * (i - last);
					last = 0;
					
//					System.out.println(i);
//					System.out.println(last);
//					System.out.println(dist);
				}
			}
		}
		
		System.out.println(dist);

	}

}
